#include "dialog.h"
#include "ui_dialog.h"
#include "QDebug"
#include "QFont"
#include "QPalette"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);

    //点击退出按钮退出
    connect(ui->pushButton_quit, &QPushButton::clicked, this, &Dialog::close);

    //点击确认按钮接受
    connect(ui->pushButton_confirm, &QPushButton::clicked, this, &Dialog::accept);

    //点击清空清空
    connect(ui->pushButton_clear, &QPushButton::clicked, ui->textEdit, &QTextEdit::clear);

    //下划线，选中的内容，点击后添加或取消下划线
    connect(ui->checkBox_underline, &QCheckBox::clicked, ui->textEdit, &QTextEdit::setFontUnderline);

    //斜体
    connect(ui->checkBox_italic, &QCheckBox::clicked, ui->textEdit, &QTextEdit::setFontItalic);

    //加粗
    connect(ui->checkBox_bold, &QCheckBox::clicked, this, &Dialog::set_bold);

    //颜色
    connect(ui->radioButton_red, &QRadioButton::clicked, this, &Dialog::set_color);
    connect(ui->radioButton_blue, &QRadioButton::clicked, this, &Dialog::set_color);
    connect(ui->radioButton_black, &QRadioButton::clicked, this, &Dialog::set_color);

}


void Dialog::set_bold(bool checked)
{
    qDebug()<<"加粗"<<checked;
    QFont font = ui->textEdit->font();//获取当前字体
    font.setBold(checked);//对字体加粗
    ui->textEdit->setFont(font);//设置字体
}

void Dialog::set_color()
{
    qDebug()<<"颜色";
    QPalette palette = ui->textEdit->palette();
    if(ui->radioButton_red->isChecked())
    {
        palette.setColor(QPalette::Text, Qt::red);
    }
    else if(ui->radioButton_black->isChecked())
    {
        palette.setColor(QPalette::Text, Qt::black);
    }
    else if(ui->radioButton_blue->isChecked())
    {
        palette.setColor(QPalette::Text, Qt::blue);
    }
    ui->textEdit->setPalette(palette);
}


Dialog::~Dialog()
{
    delete ui;
}
